package top.as.sean.biz.system.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.as.sean.biz.system.IUserPost;
import top.as.sean.dao.entity.pojo.system.UserPost;
import top.as.sean.dao.mapper.system.UserPostMapper;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 用户-岗位
 *
 * @author: ArchieSean
 * @create: 2022/11/29
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserPostImpl implements IUserPost {
    /**
     * 用户-岗位中间表
     */
    private final UserPostMapper userPostMapper;

    /**
     * 新增用户-岗位
     *
     * @param postIds 岗位ids
     * @param userId  用户id
     */
    @Override
    public void saveBatchIds(@NotNull List<Long> postIds, @NotNull Long userId) {
        //删除
        userPostMapper.delBatchByUserId(userId);
        List<UserPost> list = Lists.newArrayList();
        postIds.forEach(postId -> {
            UserPost userPost = new UserPost();
            userPost.setPostId(postId);
            userPost.setUserId(userId);
            list.add(userPost);
        });
        userPostMapper.saveBatch(list);
    }
}
